#include "sum_grad_op.h"
#include "../constant.h"
#include "../../matrix/matrix.h"
#include "../../factory/factory.h"
#include "../../factory/constant_factory.h"

SumGrad::SumGrad(Node* node, Shape* shape) : OpNode({node}){
    setOutShape(shape);
}

vector<Node*> SumGrad::getGradNodes(Node* grad) {
    Factory* factory = new ConstantFactory(Matrix(1,1,1));
    Node* ret = factory -> createNode();
    delete factory;
    return { ret };
}

void SumGrad::compute(Context* context) {
    auto nodes = *getNodeIn();
    auto shape = getOutShape();
    Matrix mat = context -> getFlowedData(nodes[0]);
    context -> setFlowedData(this, 
            Matrix(shape -> rows, shape -> cols, mat[0][0]));
}
